<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-bscatalogue__bscatalogue">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="目录名称:">
          <el-input v-model="dataForm.name" placeholder="名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="部门:">
          <el-select v-model="dataForm.department" placeholder="部门">
            <el-option label="全部" value=""></el-option>
            <el-option v-for="item in departmentSelects" :key="item.label" v-bind="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">目录查询</el-button>
        </el-form-item>
        <!-- <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item> -->
        <!-- <el-form-item>
          <el-button v-if="$hasPermission('bscatalogue:bscatalogue:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item> -->
        <!-- <el-form-item>
          <el-button v-if="$hasPermission('bscatalogue:bscatalogue:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item> -->
      </el-form>
      <el-table v-loading="dataListLoading" row-key="id" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <!-- <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column> -->
        <el-table-column prop="name" label="名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="sort" label="排序" header-align="center" align="center"></el-table-column>
        <el-table-column prop="icon" label="图标" header-align="center" align="center">
          <template slot-scope="scope">
            <svg class="icon-svg" aria-hidden="true"><use :xlink:href="`#${scope.row.icon}`"></use></svg>
          </template>
        </el-table-column>
        <el-table-column prop="department" label="部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="remark2" label="简介" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="state" label="审核状态 " header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{+scope.row.state === 0 ? '待审核' : +scope.row.state === 1 ? '已通过' : '驳回'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="state" label="驳回理由 " header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{+scope.row.state === 2 ? scope.row.opinion : '--'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('bsdemand:examine')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">审核</el-button>
            <!-- <el-button v-if="$hasPermission('bscatalogue:bscatalogue:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" :isExamine="true"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './bscatalogue-add-or-update'
import dictionaries from '@/utils/dictionaries.js'
import { mapState } from 'vuex'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      tableData: [],
      companyArr: dictionaries.companyArr,
      mixinViewModuleOptions: {
        getDataListURL: '/bscatalogue/bscatalogue/page',
        getDataListIsPage: false,
        exportURL: '/bscatalogue/bscatalogue/export',
        deleteURL: '/bscatalogue/bscatalogue',
        deleteIsBatch: true,
        requestCallback: data => {
          this.$store.commit('setCatalogueTree', data)
        }
      },
      dataForm: {
        name: '',
        department: ''
      }
    }
  },
  watch: {
    dataList: {
      handler () {
        this.tableData = []
        this.dataList.map(item => {
          if (item.state == 0) {
            this.tableData.push(item)
          }
        })
        // this.total = this.tableData.length
      }
    }
  },
  computed: {
    ...mapState(['departmentSelects'])
  },
  components: {
    AddOrUpdate
  }
}
</script>
